#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int cnt;
	cin >> cnt;
	while(cnt--){
		int n,t;
		cin >> n >> t;
		string s;
		cin >> s;
		vector<int> arr(s.size(),0);
		for(int i = 0; i < n; ++i){
			if(s[i] == '1'){
				arr[i] = -1;
				bool lf = true,rf = true;
				for(int j = 1; j <= t; ++j){
					int left = (i - j + n) % n;
					int right = (i + j) % n;
					if(lf){
						if(s[left] == '1'){
							lf = false;
						}
						if(lf){
							++arr[left];
						}
					}
					if(rf){
						if(s[right] == '1'){
							rf = false;
						}
						if(rf){
							++arr[right];
						}
					}
				}
			}
		}
		
		int maxi = 0;
		int ret = 0;
		for(int i = 0; i < n; ++i){
			if(arr[i] == 0){
				++ret;
				continue;
			}
			if(arr[i] == -1){
				int lans = 0;
				int rans = 0;
				bool lf = true,rf = true;
				for(int j = 1; j <= t; ++j){
					int left = (i - j + n) % n;
					int right = (i+j) % n;
					if(j == 1){
						if(arr[left] == -1){
							lf = false;
						}
						if(arr[right] == -1){
							rf = false;
						}
						continue;
					}
					if(lf){
						if(arr[left] == -1){
							lf = false;
						}
						if(lf){
							if(arr[left] - 1 == 0){
								++lans;
							}
						}
					}
					if(rf){
						if(arr[right] == -1){
							rf = false;
						}
						if(rf){
							if(arr[right] - 1 == 0){
								++rans;
							}
						}
					}
				}
				lans = max(lans,rans);
				maxi = max(maxi,lans);
			}
		}
		
		cout << ret + maxi;
		if(cnt) cout << endl;
	}
	
	return 0;
}

